package commonClasses.Messages;

import commonClasses.*;
import commonClasses.Messages.Msg;
import commonClasses.commonInterfaces.MsgIntf;
import commonClasses.commonInterfaces.ProtocolIntf;

/**
 *
 * @author Pozytywny!
 */
public class QueryFollowedMsg extends Msg implements MsgIntf{

    public long getItemID() {
        return _itemID;
    }

    private long _itemID = -1;

    public void receive() throws Exception {
        long dataLength = receiveUint();
        Utils.received(dataLength);
        if(dataLength != 4l) throw new Exception("długość danych: " + dataLength +
                ", oczekiwana: 4");

        _itemID = receiveUint();
        Utils.received("otrzymany item id: "+_itemID);
    }

    public void send() throws Exception {
        if(_itemID == -1)
            throw new Exception("itemID nie został zainicjalizowany");

        int mesgId[] = this.idToIntArr();
        sendIntArr(mesgId);

        int dataLength[] = longToArr(4l);
        sendIntArr(dataLength);

        int itemID[] = longToArr(_itemID);
        sendIntArr(itemID);
    }

    public QueryFollowedMsg(ProtocolIntf protocol, long itemID) {
        super(protocol, MagicNumbers.QUERY_FOLLOWED_MSG_NR);
        this._itemID = itemID;
    }

    public QueryFollowedMsg(ProtocolIntf protocol) {
        super(protocol, MagicNumbers.QUERY_FOLLOWED_MSG_NR);
    }

}
